using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Windows.Forms;
using Microsoft.VisualBasic.CompilerServices;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.CompilerServices;
using DevExpress.XtraEditors.Controls;
namespace ePlanSysOman
{
  public partial class frmCompRef
  {
    string refwt2 = "";
    clsData data = new clsData();
    string Wirenowt = "";
    string newwy = "";

    private void  // ERROR: Handles clauses are not supported in C#
GridView1_Click(object sender, System.EventArgs e)
    {
      //Dim dsall As New DataSet


      //refwt2 = Conversions.ToString(GridView1.GetRowCellValue(GridView1.GetSelectedRows(0), "WIRETIE"))
      //'    refwt = (Me.GridView1.GetRowCellValue(GridView1.se, "bacWireNo"))
      //dsall = data.getData("SELECT * FROM PTP2 WHERE WIRE_NUMBER IN(SELECT WIRE_NUMBER FROM PTP2 WHERE WIRE_END_REF ='" & refwt2 & "')")
      //grdWtWires.DataSource = dsall.Tables(0)
    }


    private void  // ERROR: Handles clauses are not supported in C#
GridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
    {

      DataSet dsall = new DataSet();
      DataSet dsw = new DataSet();

      if (tabc.SelectedTabPage.Text == "IDENTICAL") {
        try {
          refwt2 = Conversions.ToString(GridView1.GetRowCellValue(GridView1.GetSelectedRows()[0], "bacRefDes1"));
          Wirenowt = Conversions.ToString(GridView1.GetRowCellValue(GridView1.GetSelectedRows()[0], "bacWireNo"));
        } catch (Exception ex) {

        }
        //    refwt = (Me.GridView1.GetRowCellValue(GridView1.se, "bacWireNo"))
        dsall = data.getData("SELECT * FROM PTP2 WHERE WIRE_NUMBER IN(SELECT WIRE_NUMBER FROM PTP2 WHERE WIRE_END_REF ='" + refwt2 + "')");
        grdWtWires.DataSource = dsall.Tables[0];

        dsw = data.getData("SELECT * FROM TBLWIRESADD WHERE SREFDES LIKE '%WT%' AND WIRESPLID ='" + Module1.newModule.WTPL + "' AND WIRENO ='" + Wirenowt + "'");
        if (dsw.Tables[0].Rows.Count == 1) {
          newwy = dsw.Tables[0].Rows[0]["SREFDES"].ToString();

        }
        //   TextEdit1.Text = refwt2 & " IS THE SAME AS " & newwy & ", NO REWORK REQUIRED."
      }


    }

    private void  // ERROR: Handles clauses are not supported in C#
GridView3_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
    {
      DataSet dsall = new DataSet();
      DataSet dsw = new DataSet();
      if (tabc.SelectedTabPage.Text == "WITH CHANGES") {
        try {
          refwt2 = Conversions.ToString(GridView3.GetRowCellValue(GridView3.GetSelectedRows()[0], "bacRefDes1"));
          Wirenowt = Conversions.ToString(GridView3.GetRowCellValue(GridView3.GetSelectedRows()[0], "bacWireNo"));
        } catch (Exception ex) {

        }
        //    refwt = (Me.GridView1.GetRowCellValue(GridView1.se, "bacWireNo"))
        dsall = data.getData("SELECT * FROM PTP2 WHERE WIRE_NUMBER IN(SELECT WIRE_NUMBER FROM PTP2 WHERE WIRE_END_REF ='" + refwt2 + "')");
        grdWtWires.DataSource = dsall.Tables[0];

        dsw = data.getData("SELECT * FROM TBLWIRESADD WHERE SREFDES LIKE '%WT%' AND WIRESPLID ='" + Module1.newModule.WTPL + "' AND WIRENO ='" + Wirenowt + "'");
        if (dsw.Tables[0].Rows.Count == 1) {
          newwy = dsw.Tables[0].Rows[0]["SREFDES"].ToString();

        }
        // TextEdit1.Text = refwt2 & " IS THE SAME AS " & newwy & ", NO REWORK REQUIRED."
      }
    }

    private void SimpleButton1_Click(System.Object sender, System.EventArgs e)
    {
      DialogResult ans;

      ans = DevExpress.XtraEditors.XtraMessageBox.Show("Reidentify Wire-Tie?", "Confirm action", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
      if (ans == DialogResult.Yes) {
        data.ExecuteSQL(string.Concat(new string[] {
          "DELETE * FROM TBLWIRESREMOVE where WIREACTID = 'REMOVE' AND  srefdes = '",
          refwt2,
          "' AND WIRESPLID = '",
          Module1.newModule.WTPL,
          "'"
        }));
        data.ExecuteSQL(string.Concat(new string[] {
          "DELETE * FROM TBLWIRESADD where WIREACTID = 'ADD' AND  srefdes = '",
          newwy,
          "' AND WIRESPLID = '",
          Module1.newModule.WTPL,
          "'"
        }));
        data.ExecuteSQL(string.Concat(new string[] {
          "DELETE * FROM TBLWIRES where WIREACTID = 'ADD' AND  srefdes = '",
          newwy,
          "' AND WIRESPLID = '",
          Module1.newModule.WTPL,
          "'"
        }));
        data.ExecuteSQL(string.Concat(new string[] {
          "DELETE * FROM TBLWIRES where WIREACTID = 'REMOVE' AND  srefdes = '",
          refwt2,
          "' AND WIRESPLID = '",
          Module1.newModule.WTPL,
          "'"
        }));
        data.ExecuteSQL(string.Concat(new string[] {
          "DELETE * FROM TBLBACKSHOPWIRES where BACACTION = 'REMOVE' AND  BACREFDES1 = '",
          refwt2,
          "' AND BACPLID = '",
          Module1.newModule.WTPL,
          "'"
        }));
        data.ExecuteSQL(string.Concat(new string[] {
          "DELETE * FROM TBLBACKSHOPWIRES where BACACTION = 'ADD' AND  BACREFDES1 = '",
          newwy,
          "' AND BACPLID = '",
          Module1.newModule.WTPL,
          "'"
        }));
        string sQL = "INSERT INTO TBLNOTES ";
        //   sQL = (sQL & "(plNotesId,plNotes,plNotestext,plTV,plFrom,plThru) VALUES ('" & WTPL & "','" & TextEdit1.Text & "','G','0','0','0')")
        data.ExecuteSQL(sQL);
      }
      DevExpress.XtraEditors.XtraMessageBox.Show("Done");
    }

    private void  // ERROR: Handles clauses are not supported in C#
frmCompRef_Load(object sender, System.EventArgs e)
    {
      DataSet ds = new DataSet();

      ds = data.getData("SELECT bacrefdes1 as bacRefDes1,bacWireNo as bacWireNo FROM TBLBACKSHOPWIRES WHERE BACPLID ='" + Module1.newModule.WTPL + "' AND ((BACREFDES1 LIKE '%WT%') or (BACREFDES1 LIKE '%E%')) AND BACREFDES2 ='' AND BACACTION ='REMOVE' AND BACREFDES1 NOT IN(SELECT WIRE_END_REF AS BACREFDES1 FROM PTP2 WHERE PART_NUMBER ='" + Module1.newModule.wtnewh + "') AND BACREFDES1 not IN (SELECT bacrefdes2 as BACREFDES1 FROM TBLBACKSHOPWIRES WHERE BACPLID ='" + Module1.newModule.WTPL + "' AND BACREFDES2 <> '' AND BACACTION ='REMOVE')");
      grdWtReid.DataSource = ds.Tables[0];
      ds = data.getData("SELECT bacrefdes1 as bacRefDes1,bacWireNo as bacWireNo FROM TBLBACKSHOPWIRES WHERE BACPLID ='" + Module1.newModule.WTPL + "' AND ((BACREFDES1 LIKE '%WT%') or (BACREFDES1 LIKE '%E%')) AND BACREFDES2 ='' AND BACACTION ='REMOVE' AND BACREFDES1 NOT IN(SELECT WIRE_END_REF AS BACREFDES1 FROM PTP2 WHERE PART_NUMBER ='" + Module1.newModule.wtnewh + "')");
      ds = data.getData("SELECT bacrefdes1 as bacRefDes1,bacWireNo as bacWireNo FROM TBLBACKSHOPWIRES WHERE BACPLID ='" + Module1.newModule.WTPL + "' AND ((BACREFDES1 not LIKE '%WT%') or (BACREFDES1 LIKE not '%E%')) AND BACREFDES2 ='' AND BACACTION ='REMOVE' AND BACREFDES1 NOT IN(SELECT WIRE_END_REF AS BACREFDES1 FROM PTP2 WHERE PART_NUMBER ='" + Module1.newModule.wtnewh + "') AND BACREFDES1 not IN (SELECT bacrefdes2 as BACREFDES1 FROM TBLBACKSHOPWIRES WHERE BACPLID ='" + Module1.newModule.WTPL + "' AND BACREFDES2 <> '' AND BACACTION ='REMOVE')");
      grdWtReid.DataSource = ds.Tables[0];
      ds = data.getData("SELECT bacrefdes1 as bacRefDes1,bacWireNo as bacWireNo FROM TBLBACKSHOPWIRES WHERE BACPLID ='" + Module1.newModule.WTPL + "' AND ((BACREFDES1 not LIKE '%WT%') or (BACREFDES1 not LIKE '%E%')) AND BACREFDES2 ='' AND BACACTION ='REMOVE' AND BACREFDES1 NOT IN(SELECT WIRE_END_REF AS BACREFDES1 FROM PTP2 WHERE PART_NUMBER ='" + Module1.newModule.wtnewh + "')");
      grdWTchanges.DataSource = ds.Tables[0];
    }

      public frmCompRef()
    {
        InitializeComponent(); 
    }
  }
}

